package com.yz.android_baozou.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yz.android_baozou.R;
import com.yz.android_baozou.activity.MainPageDetailActivity;
import com.yz.android_baozou.bean.ColumnDetialListBean;
import com.yz.android_baozou.helper.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * Created by Administrator on 2016/11/2.
 */

public class ColumnDetialList_RecyclerAdapter extends RecyclerViewAdapterHelper<ColumnDetialListBean.DataBean> {
    //声明RecyclerView
    private RecyclerView recyclerViewColumnDetailList;

    //构造方法
    public ColumnDetialList_RecyclerAdapter(Context context, List<ColumnDetialListBean.DataBean> list, RecyclerView _recyclerViewColumnDetailList) {
        super(context, list);
        this.recyclerViewColumnDetailList = _recyclerViewColumnDetailList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        //根据布局管理器获得item布局
        final View view = inflater.inflate(R.layout.item_columndetiallist, parent, false);
        //给view设置监听
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //借助recyclerView获得点击的item的下标
                int position = recyclerViewColumnDetailList.getChildAdapterPosition(view);
                String url = list.get(position).getShare_url();
                Bundle bundle = new Bundle();
                //获得item的url
                bundle.putString("url", url);
                Intent intent = new Intent(context, MainPageDetailActivity.class);
                //借助bundle携带数据
                intent.putExtra("url", bundle);
                //根据intent跳转页面
                context.startActivity(intent);
            }
        });
        return new MylistViewHolder(view);
    }

    @Override
    //绑定item
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MylistViewHolder) {
            ((MylistViewHolder) holder).textView_author_ColumnDetialList.setText(list.get(position).getAuthor_name());
            ((MylistViewHolder) holder).textView_Content_ColumnDetialList.setText(list.get(position).getTitle());
            ((MylistViewHolder) holder).textView_type_ColumnDetialList.setText(list.get(position).getSection_name());
            Glide.with(context).load(list.get(position).getImage()).into(((MylistViewHolder) holder).imageView_show_ColumnDetialList);
        }
    }

    //生成item的实体类
    class MylistViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView_show_ColumnDetialList;
        private TextView textView_Content_ColumnDetialList;
        private TextView textView_author_ColumnDetialList;
        private TextView textView_type_ColumnDetialList;

        public MylistViewHolder(View itemView) {
            super(itemView);
            imageView_show_ColumnDetialList = (ImageView) itemView.findViewById(R.id.imageView_show_ColumnDetialList);
            textView_Content_ColumnDetialList = (TextView) itemView.findViewById(R.id.textView_Content_ColumnDetialList);
            textView_author_ColumnDetialList = (TextView) itemView.findViewById(R.id.textView_author_ColumnDetialList);
            textView_type_ColumnDetialList = (TextView) itemView.findViewById(R.id.textView_type_ColumnDetialList);
        }
    }

}
